<template>
  <img v-if="showGoToHt" :src="icon || src" :alt="title" :title="title" style="cursor: pointer" @click="handleClick" />
</template>

<script>
import cookie from '../../utils/cookie.js';
import icon from './assets/nav_bt_set.png';

export default {
  name: 'backstage',
  props: {
    icon: { default: undefined },
    title: { default: '前往后台' },
    address: { default: '/main' },
  },
  data() {
    return {
      src: icon,
      showGoToHt: String(cookie.get('no_login_ht')).trim() !== '0',
    };
  },
  methods: {
    handleClick() {
      if (typeof this.$attrs.onOnClick === 'function') {
        this.$attrs.onOnClick();
        return;
      }
      if (this.address) {
        window.open(this.address);
      }
    },
  },
};
</script>

<style scoped></style>
